<!--#Include File="../conn.asp" -->
<!--#Include File="comm/inc.asp" -->
<!--#Include File="../include/cls_editor.asp" -->
<%
'====================================================================
'= Team Elite - Elite Article System
'= Copyright (c) 2005 - 2006 Eason Chan All Rights Reserved.
'=-------------------------------------------------------------------
'= 版权协议：
'=	GPL (The GNU GENERAL PUBLIC LICENSE Version 2, June 1991)
'=-------------------------------------------------------------------
'= 文件名称：/Manager/Admin_ArtTemplate.asp
'= 摘    要：后台-文章管理文件
'=-------------------------------------------------------------------
'= 最后更新：eason007
'= 最后日期：2005-12-21
'====================================================================

Call EA_Manager.Chk_IsMaster

If Not EA_Manager.Chk_Power(Admin_Power,"15") Then 
	ErrMsg=str_Comm_NotAccess
	Call EA_Manager.Error(1)
End If

Dim Atcion
Atcion=Request.QueryString ("atcion")

Select Case LCase(Atcion)
Case "add"
	Call Add
Case "save"
	Call Save
Case "del"
	Call Del
Case Else
	Call Main
End Select
Call EA_Pub.Close_Obj
Set EA_Pub=Nothing
	
Sub Main
	Dim Count,PageCount,Page,OutStr,i
	Dim FieldName(0),FieldValue(0),TopicList
	Dim Temp,ListBlock
	
	Page=EA_Pub.SafeRequest(3,"page",0,1,0)

	PageContent=Template.LoadTemplate("admin_arttemplate_list.htm")


	Template.SetVariable "Language_Comm_ListEmpty",str_Comm_ListEmpty,PageContent
	Template.SetVariable "Language_Comm_Bar_Operation",str_Comm_Bar_Operation,PageContent
	Template.SetVariable "Language_Comm_Edit_Operation",str_Comm_Edit_Operation,PageContent
	Template.SetVariable "Language_Comm_Alert_Del_Operation",str_Comm_Alert_Del_Operation,PageContent
	Template.SetVariable "Language_Comm_Del_Operation",str_Comm_Del_Operation,PageContent

	Template.SetVariable "Language_OperationNotice",str_OperationNotice,PageContent
	Template.SetVariable "Language_ArticleTemplate_Help",str_ArticleTemplate_Help,PageContent

	Template.SetVariable "Language_ArticleTemplate_TemplateList",str_ArticleTemplate_TemplateList,PageContent
	Template.SetVariable "Language_ArticleTemplate_AddTemplate",str_ArticleTemplate_AddTemplate,PageContent
	Template.SetVariable "Language_ArticleTemplate_TemplateName",str_ArticleTemplate_TemplateName,PageContent


	ListBlock=Template.GetBlock("list",PageContent)

	Count=EA_M_DBO.Get_ArticleTemp_Total()(0,0)
	If Count>0 Then 
		Template.SetVariable "ListTempty","none",PageContent

		TopicList=EA_M_DBO.Get_ArticleTemp_List(Page,15)
	
	    For i=0 To Ubound(TopicList,2)
			Temp=ListBlock
  
			Template.SetVariable "TemplateID",TopicList(0,i),Temp
			Template.SetVariable "TemplateName",TopicList(1,i),Temp

			Template.SetBlock "list",Temp,PageContent
		Next

		Template.SetVariable "PageListNav",EA_Manager.PageList(15,Count,Page,FieldName,FieldValue),PageContent
	End If
	Template.CloseBlock "list",PageContent


	Template.BaseReplace PageContent
	Template.OutStr PageContent
End Sub

Sub Add
	Dim PostId,Title,Content
	Dim EA_Editor
	Dim Temp

	PostId=EA_Pub.SafeRequest(3,"postid",0,0,0)
	Set EA_Editor=New cls_Editor
	
	Temp=EA_M_DBO.Get_ArticleTemp_Info(PostId)
	If IsArray(Temp) Then 
		Title=Temp(0,0)
		Content=Temp(1,0)
	End If

	EA_Editor.EditorType=EA_Pub.SysInfo(23)
	EA_Editor.Value=Content

	PageContent=Template.LoadTemplate("admin_arttemplate_option.htm")


	Template.SetVariable "Language_Comm_Save_Button",str_Comm_Save_Button,PageContent
	Template.SetVariable "Language_Comm_Reset_Button",str_Comm_Reset_Button,PageContent

	Template.SetVariable "Language_OperationNotice",str_OperationNotice,PageContent
	Template.SetVariable "Language_ArticleTemplate_Help",str_ArticleTemplate_Help,PageContent

	Template.SetVariable "Language_ArticleTemplate_TemplateList",str_ArticleTemplate_TemplateList,PageContent
	Template.SetVariable "Language_ArticleTemplate_AddTemplate",str_ArticleTemplate_AddTemplate,PageContent
	Template.SetVariable "Language_ArticleTemplate_Input_Template",str_ArticleTemplate_Input_Template,PageContent
	Template.SetVariable "Language_ArticleTemplate_TemplateName",str_ArticleTemplate_TemplateName,PageContent

	Template.SetVariable "TemplateID",PostId,PageContent
	Template.SetVariable "TemplateTitle",Title,PageContent
	Template.SetVariable "TemplateContent",EA_Editor.Create,PageContent


	Template.BaseReplace PageContent
	Template.OutStr PageContent

End Sub

Sub Save
	Call EA_Pub.Chk_Post
	
	Dim Title,Content
	Dim PostId
	Dim i
	
	PostId=EA_Pub.SafeRequest(3,"postid",0,0,0)
	Title=EA_Pub.SafeRequest(2,"name",1,"",0)

	For i = 1 To Request.Form("content").Count
	  Content = Content & Request.Form("content")(i)
	Next
	
	If Title="" Or Len(Title)>150 Then
		ErrMsg="对不起，模版名称长度不符！"
		ErrMsg=ErrMsg&"<li>长度等于0或大于150"
		Call EA_Manager.Error(1)
	End If
	
	If Rs.State=1 Then rs.Close
	If PostId<>0 Then
		Sql="Select * From [NB_ArticleTemplate] Where [Id]="&PostId
		rs.Open Sql,Conn,2,2
	Else
		rs.Open "NB_ArticleTemplate",Conn,2,2
		rs.AddNew
	End If
		rs("Title")=Title
		rs("Content")=Content
		rs.update
	Rs.Close:Set Rs=Nothing
	
	Call EA_Pub.Close_Obj
	Set EA_Pub=Nothing
	
	Response.Redirect "admin_arttemplate.asp"
End Sub

Sub Del
	Call EA_Pub.Chk_Post
	
	Dim PostId
	PostId=EA_Pub.SafeRequest(3,"postid",0,0,0)
	
	EA_M_DBO.Set_ArticleTemp_Del PostId
	
	Call EA_Pub.Close_Obj
	Set EA_Pub=Nothing

	Response.Redirect Request.ServerVariables("HTTP_REFERER")
End Sub
%>